package ufs.dcomp.mgemeos.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import ufs.dcomp.mgemeos.dao.Conexao;
import ufs.dcomp.mgemeos.perfis.Administrador;

/**
 *
 * @author Luiz Marcus
 * @modificação 07/01/11
 */
public class AdministradorDAO implements interface_dao.IAdministrador{

    //private static String inserir = "insert into sgemeos (login,senha) values (?,?) ";
    private static String atualizar = "update administrador set login = ?,senha = ? where administradorID=?";
    private static String obter_login = "select * from administrador where login = ? ";

    /**
     * Atualizar dados do administrador
     */
   
    
    @Override
    public boolean atualizarAdministrador(String login, String senha) {
        Conexao conexao = new Conexao();
        Connection con = conexao.getConnection();
        PreparedStatement pst;
        try {
            pst = con.prepareStatement(atualizar);
            pst.setString(1, login);
            pst.setString(2, senha);
            pst.setString(3, "2011");
            pst.executeUpdate();
            pst.close();
            con.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    
    
    @Override
    public Administrador obterAdministrador(String login) {
        Administrador admin = null;
        Conexao conexao = new Conexao();
        Connection con = conexao.getConnection();        
        PreparedStatement pst;
        try {
            pst = con.prepareStatement(obter_login);
            pst.setString(1, login);
            ResultSet rs = pst.executeQuery();
            if (rs.next()) {

                admin = new Administrador();
                admin.setIdAdministrador("2011");
                admin.setLogin(rs.getString(1));
                admin.setSenha(rs.getString(2));
            }
            rs.close();
            pst.close();
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return admin;
    }
}
